var http = require('http')
var fs = require('fs')
var server = http.createServer()

server.on('request', function (req, res) {
    var wwwDir = './public';
    var filePath = '/index.html';
    if (req.url !== '/'){
        filePath = req.url
    }
    fs.readFile(wwwDir+filePath,function (err,data) {
        console.log(wwwDir+filePath)
        if (err){
            return res.end('404 not found')
        }
        // res.setHeader('Content-type', 'text/html;charset=utf-8')
        res.end(data)
    })
})

server.listen(3000, function () {
    console.log('server is running')
})